<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * Mall Home模板
 */
namespace Addon\MallTemplateHome\Controller;
use Addon\MallTemplateHome\Controller\CommonController;

/**
 * Home模板
 */
class MallController extends CommonController {
    
	//商城首页
	public function Goods(){
		
		$m_mall_content = M('mall_content');
		
		$map['id'] = I('param.id');
		//$map['form_id'] = 0;
		$map['type'] = get_mall_model_conf('MALL_GOODS');
		$map['status'] = 1;
		$data = $m_mall_content->where($map)->find();
		$this->assign('goods',$data);
		
		$this->view();
	}
	
	//商城首页
	public function Index(){
		
		$express_money = $this->getExpressMoney();
		$express_begin_money = $this->getExpressBeginMoney();
		$notice = $this->getNotice();//获得公告
		$logo = $this->getLogo();//获得logo
		$goods = $this->getGoods();//获得商品 
		$classify = $this->getClassify();//获得分类
		$address = $this->getAddress();//获得默认地址
		
	
		$this->assign('express_money',$express_money);
		$this->assign('express_begin_money',$express_begin_money);
		$this->assign('logo',$logo);
		$this->assign('notice',$notice);
		$this->assign('address',$address);
		$this->assign('goods',$goods);
		$this->assign('classify',$classify);
		
		
		$this->view();
	}
	
	//商城公告详情
	public function Notice(){
		
		$m_cms_content = M('cms_content');
		
		$map['id'] = I('param.id');
		$map['form_id'] = 74;
		$map['type'] = 2;

		$data = $m_cms_content->where($map)->find();
	
		$this->assign('data',$data);
		
		$this->view();
		
	}
	
	//商城首页
	public function Express(){
		
	
		$m_mall_content = M('mall_content');
		$map['type'] = get_mall_model_conf('MALL_ORDER_INFO');
		
		$map['name'] = I('param.order_id');
		$map['status'] = 1;
		
	
		$list = $m_mall_content->where($map)->order('time desc')->select();
	
	
		
		$this->assign('list',$list);
	
		
		$this->view();
	}
	
	public function Money(){
		
	
		$m_mall_money = M('mall_money');
		
		$map['uid'] = getUID();
		$map['status'] = array('in','1,2');
		
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_money->where($map)->order('time desc')->page($_GET['p'].',10')->select();
	
		$info = $this->info;
		$count      = $m_mall_money->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\AddonPage($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show($info['addon']);// 分页显示输出
		$this->assign('pages',$show);

		
		$this->assign('list',$list);
	
		
		$this->view();
	}

	//获得默认地址
	public function getAddress(){
		
		$m_mall_content = M('mall_content');
		
		$map['uid'] = getUID();
		$map['form_id'] = 0;
		$map['type'] = get_mall_model_conf('MALL_USER_ADDRESS');
		$map['status'] = 1;
		$map['sort'] = 1;

	
		$data = $m_mall_content->where($map)->find();
	
	
		return $data;
		
		
	}
	
	//获得最新公告
	public function getNotice(){
		
		$m_cms_content = M('cms_content');
		
		$map['form_id'] = 74;
		$map['type'] = 2;
		$map['status'] = 1;

	
		$list = $m_cms_content->where($map)->order('time desc')->limit(1)->select();
	
	
	
		return $list[0];
		
		
	}
	
	//获得logo
	public function getLogo(){
		
		$m_cms_content = M('cms_content');
		
		$map['id'] = 75;

	
		$data = $m_cms_content->where($map)->find();
	
	
	
		return $data['img'];
		
		
	}
	
	//获得商品列表
	public function getGoods(){
		
		$m_mall_content = M('mall_content');
		
		$map['type'] = get_mall_model_conf('MALL_GOODS');
		
		$form_id = I('param.form_id');
		
		if($form_id!=null){
			
			$map['form_id'] = $form_id;
		
		}
		
		$map['status'] = 1;
		
		$list = $m_mall_content->where($map)->order('sort desc')->select();
	
	
	
		return $list;
		
		
	}
	
	//获得商品分类
	public function getClassify(){
		
		$m_mall_content = M('mall_content');
		
		$map['type'] = get_mall_model_conf('MALL_CLASSIFY');
		$map['form_id'] = 0;
		$map['status'] = 1;
		
		$form_id = I('param.form_id');
		
		$list = $m_mall_content->where($map)->order('sort desc')->select();
	
		foreach($list as $i=>$k){
			
			if($list[$i]['id']==$form_id){
				
				
				$list[$i]['class'] = 'class="hover"';
				
			}
			
			
		}
		
		return $list;
		
		
	}
	
	
	//购物车
	public function Cart(){
		
		$express_begin_money = $this->getExpressBeginMoney();
		
		$express_money = $this->getExpressMoney();
		$address_node = $this->getAddressNode();
		$address = $this->getAddress();
		if(empty($address)){
			
			$this->error('请添加地址', U('Home/OAuth/Address/Addon/WeiXin'));
			
		}
		
		$this->assign('address_node',$address_node);
		$this->assign('express_money',$express_money);
		$this->assign('express_begin_money',$express_begin_money);
		$this->assign('address',$address);
		
		
		$this->view();
	}
	
	
	//获得商品列表
	public function getAddressNode(){
		
		$m_mall_content = M('mall_content');
		
		$map['type'] = get_mall_model_conf('MALL_MY_EXPRESS_TAKE');

		$map['status'] = 1;
		
		$list = $m_mall_content->where($map)->order('sort desc')->select();
		
		foreach($list as $i=>$k){
			
			if($list[$i]['id']==142 or $list[$i]['id']==143){
				
				unset($list[$i]);
			}
		}
		
	
	
		return $list;
		
		
	}
	
	//获得快递
	public function getExpressMoney(){
		
	
		$express_money = get_mall_order_conf('MALL_ORDER_EXPRESS_MONEY');
	
		return $express_money;
		
		
	}
	
	//获得快递
	public function getExpressBeginMoney(){
		
	
		$express_begin_money = get_mall_order_conf('MALL_ORDER_EXPRESS_BEGIN_MONEY');
	
		return $express_begin_money;
		
	}
	
	
	//订单详情
	public function OrderDetail(){
		
	
		$this->view();
	}
	
	//个人中心
	public function MyInfo(){
		
		
		$user = getUserInfo();
		
		$this->assign('user',$user);
		
		
		$this->view();
	}
	
	//订单信息
	public function Order(){
		
		$m_mall_order = M('mall_order');
		
		$type = I('param.type','','');
		
		if($type==1){
			
			$map['form_order_id'] = 0;
			$map['status'] = 1;
			
		}else if($type==2){
			
			$map['form_order_id'] = 0;
			$map['status'] = array('in','2,3,4,5,7');
			
			
		}else if($type==3){
			
			$map['form_order_id'] = 0;
			$map['status'] = 6;
	
		}
		$map['order_type'] = 1;
		$map['uid'] = getUID();
		
	
		$_GET['p']=$_GET['p']?$_GET['p']:1;
		$list = $m_mall_order->where($map)->order('time desc')->page($_GET['p'].',5')->select();
	
		$info = $this->info;
		$count      = $m_mall_order->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\AddonPage($count,5);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show($info['addon']);// 分页显示输出
		$this->assign('pages',$show);
		
		foreach($list as $i=>$k){
			
			$down_map['form_order_id'] = $list[$i]['order_id'];
			
			$list[$i]['down'] = $m_mall_order->where($down_map)->order('time desc')->select();
			
		}
		
		
		$this->assign('list',$list);
		$this->assign('type',$type);
		
		
		
		$this->view();
	}
	
	
	
}